package ExtendDemo.demo14;

import java.io.*;
import java.net.Socket;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Socket s=new Socket("192.168.0.101",10004);

        //本地的流，用来读取本地文件的
        BufferedInputStream bis=new BufferedInputStream(new FileInputStream("1.jpg"));

        //写到服务器 --- 网络中的流
        OutputStream os = s.getOutputStream();
        BufferedOutputStream bos=new BufferedOutputStream(os);
        int len;
        while ((len=bis.read())!=-1){
            bos.write(len);//通过网络写到服务器中
        }
        //给服务器一个结束标记，告诉服务器文件已经传输完毕
        s.shutdownOutput();


        BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
        String line;
        while ((line= br.readLine())!=null){
            System.out.println(line);
        }

        bis.close();
        s.close();

    }
}
